package com.example.service;

import com.example.entity.Account;
import com.example.entity.LevelTwo;
import com.example.mapper.LevelTwoMapper;
import com.example.utils.TokenUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 二级机构
 **/
@Service
public class LevelTwoService {

    @Resource
    private LevelTwoMapper leveltwoMapper;

    /**
     * 新增
     */
    public void add(LevelTwo leveltwo) {
        Account currentUser = TokenUtils.getCurrentUser();
        leveltwoMapper.insert(leveltwo);
    }

    /**
     * 删除
     */
    public void deleteById(Integer id) {
        leveltwoMapper.deleteById(id);
    }

    /**
     * 批量删除
     */
    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
            leveltwoMapper.deleteById(id);
        }
    }

    /**
     * 修改
     */
    public void updateById(LevelTwo leveltwo) {
        leveltwoMapper.updateById(leveltwo);
    }

    /**
     * 根据ID查询
     */
    public LevelTwo selectById(Integer id) {
        return leveltwoMapper.selectById(id);
    }
    /**
     * 查询所有
     */
    public List<LevelTwo> selectAll(LevelTwo leveltwo) {
        return leveltwoMapper.selectAll(leveltwo);
    }

    /**
     * 分页查询
     */
    public PageInfo<LevelTwo> selectPage(LevelTwo leveltwo, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<LevelTwo> list = leveltwoMapper.selectAll(leveltwo);
        return PageInfo.of(list);
    }

}